Keyshot 11.3.3 scripting to edit animation?

When I’m animating, I have an odd way to organize my timeline, which involves a good amount of moving certain animations (usually fades and translations) to a specific time and duration. I wanted to look into if I could make a function for this to make it a bit faster. Turns out, it’s way more complicated than I wanted to sign up for, so I’m more or less throwing in the towel, but I want to see if someone has the solution.
Here’s more or less what I ended up with:

#AUTHOR ntoma
#VERSION 0.0.0
#Write description of the script here, and put your code after these lines.

#Get the active scene
scene = lux.getSceneTree()

#Get selected nodes or parts
selected_nodes = scene.getSelected()

if not selected_nodes:
    print("No nodes are selected. Please select a node first.")
else:
    for node in selected_nodes:
        #Print the name of the selected node
        print(f"Selected node name: {node.getName()}")
        
        #Check if the node has animations
        if node.isAnimation():
            print(f"The selected node '{node.getName()}' has animations.")
            
            node.setAnimationFrame(0.6)  # set start time
            node.setAnimationTime(0.2)  # set length
                    
            #Apply changes to the scene
            scene.update()
                    
            print(f"Animation for node '{node.getName()}' updated to start at 600 ms.")
            break
        else:
            print(f"The selected node '{node.getName()}' does not have animations.")

The error I keep consistently getting is

Traceback (most recent call last):
File “”, line 22, in
AttributeError: ‘lux.SceneNode’ object has no attribute ‘setAnimationFrame’

.isAnimation on the node brings back true, it 100% has an animation, it just seems to refuse to want to interact with it. Maybe there’s some function I’m unaware of to make it refer to just the animation in the node? There API lists these functions to set the animation frame/time, I must be missing something. Thanks.

Hi Nick,

The error you are getting means that there is no method called “setAnimationFrame” on a lux.SceneNode object. The “setAnimationFrame” function is actually a global function, attached to the lux namespace. Its purpose is to set the animation time in the timeline.
The “setAnimationTime” function is also global, and its purpose is also to set the animation time, just using a different unit (time instead of frames).

Unfortunately there is no scripting API to manipulate individual animations as of yet. You will not be able to set the starting time nor duration of an animation using python scripts.

1 Like